home *** CD-ROM | disk | FTP | other *** search
- unit Dirlist;
-
- { This unit defines the various versions of ScanDir called from MAKEMIU.PAS }
- { when each of the 4 start buttons are clicked. It makes use of $IFDEFs to }
- { tailor the unit to the Delphi version. }
-
- interface
-
- uses SysUtils;
-
- type
- { TScanDirCallBack is defined with the pascal calling convention for Win32. }
- { The 16 bit version does not specify this keyword as it is invalid in that }
- { environment and all parameters are passed on the stack. }
-
- {$IFNDEF WIN32}
- TScanDirCallBack = function(CurrentFile: string; Attr: Byte): Boolean;
- {$ELSE}
- TScanDirCallBack = function(CurrentFile: string; Attr: Byte): Boolean; pascal;
-
- { These three callbacks are used to demonstrate how MakeMethodInstance32Reg }
- { handles routines with 1,2 or 3 parameters optimised into registers }
-
- TScanDirCallBackR1 = function(CurrentFile: string): Boolean;
- TScanDirCallBackR2 = function(CurrentFile: string; Attr: Byte): Boolean;
- TScanDirCallBackR3 = function(CurrentFile: string; Attr: Byte; Size: Integer): Boolean;
- {$ENDIF}
-
- function ScanDir(const Dir: string; CallBack: TScanDirCallBack): Integer;
- {$IFDEF WIN32}
- function ScanDirR1(const Dir: string; CallBack: TScanDirCallBackR1): Integer;
- function ScanDirR2(const Dir: string; CallBack: TScanDirCallBackR2): Integer;
- function ScanDirR3(const Dir: string; CallBack: TScanDirCallBackR3): Integer;
- {$ENDIF}
-
- implementation
-
- function ScanDir(const Dir: string; CallBack: TScanDirCallBack): Integer;
- var
- SearchRec: TSearchRec;
- RC: Integer;
- WStr: string;
- Cancelled: Boolean;
-
- begin
- Result := 0;
- Cancelled := False;
- if Dir[Length(Dir)] = '\' then
- WStr := Dir + '*.*'
- else
- WStr := Dir + '\*.*';
- RC := FindFirst(WStr,faAnyFile,SearchRec);
- While (RC = 0) and not Cancelled do
- begin
- if SearchRec.Attr <> faVolumeId then
- begin
- Inc(Result);
- if Assigned(CallBack) then
- Cancelled := CallBack(SearchRec.Name,SearchRec.Attr);
- end;
- RC := FindNext(SearchRec);
- end;
- end;
-
- {$IFDEF WIN32}
-
- { The following functions were defined to demonstrate how }
- { MskeMethodInstance32Reg handles the register calling convention }
-
- { This routine accepts a callback which is defined so that a single }
- { parameter is optimised into registers (Name) }
-
- function ScanDirR1(const Dir: string; CallBack: TScanDirCallBackR1): Integer;
- var
- SearchRec: TSearchRec;
- RC: Integer;
- WStr: string;
- Cancelled: Boolean;
-
- begin
- Result := 0;
- Cancelled := False;
- if Dir[Length(Dir)] = '\' then
- WStr := Dir + '*.*'
- else
- WStr := Dir + '\*.*';
- RC := FindFirst(WStr,faAnyFile,SearchRec);
- While (RC = 0) and not Cancelled do
- begin
- if SearchRec.Attr <> faVolumeId then
- begin
- Inc(Result);
- if Assigned(CallBack) then
- Cancelled := CallBack(SearchRec.Name);
- end;
- RC := FindNext(SearchRec);
- end;
- end;
-
- { This routine accepts a callback which is defined so that two }
- { parameters are optimised into registers (Name and Attr) }
-
- function ScanDirR2(const Dir: string; CallBack: TScanDirCallBackR2): Integer;
- var
- SearchRec: TSearchRec;
- RC: Integer;
- WStr: string;
- Cancelled: Boolean;
-
- begin
- Result := 0;
- Cancelled := False;
- if Dir[Length(Dir)] = '\' then
- WStr := Dir + '*.*'
- else
- WStr := Dir + '\*.*';
- RC := FindFirst(WStr,faAnyFile,SearchRec);
- While (RC = 0) and not Cancelled do
- begin
- if SearchRec.Attr <> faVolumeId then
- begin
- Inc(Result);
- if Assigned(CallBack) then
- Cancelled := CallBack(SearchRec.Name,SearchRec.Attr);
- end;
- RC := FindNext(SearchRec);
- end;
- end;
-
- { This routine accepts a callback which is defined so that three }
- { parameters are optimised into registers (Name,Attr and size) }
-
- function ScanDirR3(const Dir: string; CallBack: TScanDirCallBackR3): Integer;
- var
- SearchRec: TSearchRec;
- RC: Integer;
- WStr: string;
- Cancelled: Boolean;
-
- begin
- Result := 0;
- Cancelled := False;
- if Dir[Length(Dir)] = '\' then
- WStr := Dir + '*.*'
- else
- WStr := Dir + '\*.*';
- RC := FindFirst(WStr,faAnyFile,SearchRec);
- While (RC = 0) and not Cancelled do
- begin
- if SearchRec.Attr <> faVolumeId then
- begin
- Inc(Result);
- if Assigned(CallBack) then
- Cancelled := CallBack(SearchRec.Name,SearchRec.Attr,SearchRec.Size);
- end;
- RC := FindNext(SearchRec);
- end;
- end;
- {$ENDIF}
-
- end.
-